// pages/photo/index.js
const App = getApp()
var loadMore=function(user_id,page,that){
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 20000
    })
    wx.request({
      url: 'https://www.sjwwljs.cn/index.php/api/Order/getUserList',
      data: {
        user_id:user_id,
        page:page,
        },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
            'content-type': 'application/json'
      },
      success: function(res){
         if(res.data.mate.code==0){
           wx.hideToast()
            var dataList_=that.data.orderList
             for(var i=0;i<res.data.list.length;i++){
                dataList_.push(res.data.list[i])
             }
              that.setData({
                 orderList : dataList_,
                 page:page+5,
                 length:res.data.list.length
            })
         }
      },
      complete: function() {
         wx.hideToast()
      }
    })
}
Page({
  data:{
    systemHeight:0,
    systemHeight:0,
    scrollTop:0,
    orderList:[],
    page:0,
    length:0
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
     var that=this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          systemHeight:res.windowHeight-135,
          systemWidth:res.windowWidth
        })
      }
    })
    
   // loadMore(wx.getStorageSync('user_id'),that.data.page,that)
  },
  onShow:function(){
    var that=this
    that.setData({
      orderList:[],
      page:0
    })
    loadMore(wx.getStorageSync('user_id'),that.data.page,that)
  },
  onPullDownRefresh:function(){
       var that=this
    that.setData({
      orderList:[],
       page:0
    })
    loadMore(wx.getStorageSync('user_id'),that.data.page,that)
  },
   //页面滑动到底部
   bindDownLoad:function(){   
       var that = this;
       loadMore(wx.getStorageSync('user_id'),that.data.page,that);
   },
    scroll:function(event){
        this.setData({
            scrollTop : event.detail.scrollTop
        });
    },

    //删除一个订单
    del_this_order:function(e){
      var that=this
      var id=e.currentTarget.dataset.id
      wx.showModal({
        title: '温馨提示',
        content: '是否需要删除该条信息?',
        success: function(res) {
          if (res.confirm) {
            App.HttpService.delOrder({id:id})
            .then(data=>{
              if(data.meat.code=='0'){
                that.onload();
              }else{
                wx.showToast({
                          title: res.meat.message,
                              icon: 'success',
                                  duration: 2000
                                })
              }
            })
          }
        }
      })
    },
    onload:function(){
      var that=this
      wx.showToast({
             title: '加载中',
             icon: 'loading',
             duration: 20000
       })
       wx.request({
      url: 'https://www.sjwwljs.cn/index.php/api/Order/getUserList',
      data: {
        user_id:wx.getStorageSync('user_id'),
        page:0,
        },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      header: {
            'content-type': 'application/json'
      },
      success: function(res){
         if(res.data.mate.code==0){
             wx.hideToast()
            var dataList_=res.data.list
              that.setData({
                 orderList : dataList_,
                 page:5,
                 length:dataList_.length
            })
         }
      }
    })
    },

save_order:function(){
  wx.navigateTo({
    url: '../confirm/index',
  })
},
select_goods:function(){
  wx.switchTab({
    url: '/pages/classify/index',
  })
},
showOrderBj:function(e){
  var type_=e.currentTarget.dataset.type
  var id=e.currentTarget.dataset.id
  if(id=='0'||id==''){
    wx.showToast({
      title: '暂无数据',
      icon: 'loading',
      duration: 1000
    })
    return
  }
  wx.navigateTo({
    url: '../show/orders/index?id='+id+'&type='+type_,
  })

  }    
})